<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
    <meta name="description" content="Draw a rectangle on the globe surface">
    <meta name="cesium-sandcastle-labels" content="Development">
    <title>Cesium Demo</title>
    <script type="text/javascript" src="../Sandcastle-header.js"></script>
    <script type="text/javascript" src="../../../Build/CesiumUnminified/Cesium.js" nomodule></script>
    <script type="module" src="../load-cesium-es6.js"></script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
    @import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
    'use strict';
//Sandcastle_Begin
var viewer = new Cesium.Viewer('cesiumContainer');
viewer.extend(Cesium.viewerCesiumInspectorMixin);
var scene = viewer.scene;
var ellipsoid = scene.globe.ellipsoid;

var id1 = '1';
var id2 = '2';
var id3 = '3';

var rectangle = Cesium.Rectangle.fromDegrees(-100.0, 30.0, -99.0, 31.0);
var center1 = Cesium.Rectangle.center(rectangle);
center1 = ellipsoid.cartographicToCartesian(center1);
var offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center1), 100000, new Cesium.Cartesian3());

var i1 = new Cesium.GeometryInstance({
    id: id1,
    geometry : new Cesium.RectangleGeometry({
        rectangle : rectangle,
        extrudedHeight : 30000.0,
        height : 10000.0,
        vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
        offsetAttribute: Cesium.GeometryOffsetAttribute.TOP
    }),
    attributes: {
        color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.5)),
        offset: Cesium.OffsetGeometryInstanceAttribute.fromCartesian3(offset)
    }
});
var o1 = new Cesium.GeometryInstance({
    id: id1,
    geometry : new Cesium.RectangleOutlineGeometry({
        rectangle : rectangle,
        extrudedHeight : 30000.0,
        height : 10000.0,
        offsetAttribute: Cesium.GeometryOffsetAttribute.TOP
    }),
    attributes : {
        color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.WHITE),
        offset: Cesium.OffsetGeometryInstanceAttribute.fromCartesian3(offset)
    }
});

rectangle = Cesium.Rectangle.fromDegrees(-99.0, 30.0, -98.0, 31.0);
var center2 = Cesium.Rectangle.center(rectangle);
center2 = ellipsoid.cartographicToCartesian(center2);

var i2 = new Cesium.GeometryInstance({
    id: id2,
    geometry : new Cesium.RectangleGeometry({
        rectangle : rectangle,
        extrudedHeight : 30000.0,
        height : 10000.0,
        vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
        offsetAttribute: Cesium.GeometryOffsetAttribute.TOP
    }),
    attributes: {
        color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(0.0, 1.0, 0.0, 0.5)),
        offset: Cesium.OffsetGeometryInstanceAttribute.fromCartesian3(Cesium.Cartesian3.ZERO)
    }
});
var o2 = new Cesium.GeometryInstance({
    id: id2,
    geometry : new Cesium.RectangleOutlineGeometry({
        rectangle : rectangle,
        extrudedHeight : 30000.0,
        height : 10000.0,
        offsetAttribute: Cesium.GeometryOffsetAttribute.TOP
    }),
    attributes : {
        color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.WHITE),
        offset: Cesium.OffsetGeometryInstanceAttribute.fromCartesian3(Cesium.Cartesian3.ZERO)
    }
});

rectangle = Cesium.Rectangle.fromDegrees(-98.0, 30.0, -97.0, 31.0);
var center3 = Cesium.Rectangle.center(rectangle);
center3 = ellipsoid.cartographicToCartesian(center3);
offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center3), 100000, new Cesium.Cartesian3());
var i3 = new Cesium.GeometryInstance({
    id: id3,
    geometry : new Cesium.RectangleGeometry({
        rectangle : rectangle,
        extrudedHeight : 30000.0,
        height : 10000.0,
        vertexFormat : Cesium.PerInstanceColorAppearance.VERTEX_FORMAT,
        offsetAttribute: Cesium.GeometryOffsetAttribute.ALL

    }),
    attributes: {
        color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(0.0, 0.0, 1.0, 0.5)),
        offset: Cesium.OffsetGeometryInstanceAttribute.fromCartesian3(offset)
    }
});
var o3 = new Cesium.GeometryInstance({
    id: id3,
    geometry : new Cesium.RectangleOutlineGeometry({
        rectangle : rectangle,
        extrudedHeight : 30000.0,
        height : 10000.0,
        offsetAttribute: Cesium.GeometryOffsetAttribute.ALL
    }),
    attributes : {
        color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.WHITE),
        offset: Cesium.OffsetGeometryInstanceAttribute.fromCartesian3(offset)
    }
});

var p = scene.primitives.add(new Cesium.Primitive({
    geometryInstances : [i1, i2, i3],
    appearance : new Cesium.PerInstanceColorAppearance({
        closed : true
    }),
    asynchronous : false
}));
var o = scene.primitives.add(new Cesium.Primitive({
    geometryInstances : [o1, o2, o3],
    appearance : new Cesium.PerInstanceColorAppearance({
        flat : true,
        renderState : {
            lineWidth : Math.min(2.0, scene.maximumAliasedLineWidth)
        }
    }),
    asynchronous : false
}));

Sandcastle.addToolbarButton('1', function() {
    var attributes = p.getGeometryInstanceAttributes(id1);
    offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center1), 150000, new Cesium.Cartesian3());
    attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);

    attributes = o.getGeometryInstanceAttributes(id1);
    offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center1), 150000, new Cesium.Cartesian3());
    attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);
});
Sandcastle.addToolbarButton('2', function() {
    var attributes = p.getGeometryInstanceAttributes(id2);
    offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center2), 100000, new Cesium.Cartesian3());
    attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);

    attributes = o.getGeometryInstanceAttributes(id2);
    offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center2), 100000, new Cesium.Cartesian3());
    attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);
});
Sandcastle.addToolbarButton('3', function() {
    var attributes = p.getGeometryInstanceAttributes(id3);
    offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center3), 150000, new Cesium.Cartesian3());
    attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);

    attributes = o.getGeometryInstanceAttributes(id3);
    offset = Cesium.Cartesian3.multiplyByScalar(ellipsoid.geodeticSurfaceNormal(center3), 150000, new Cesium.Cartesian3());
    attributes.offset = Cesium.OffsetGeometryInstanceAttribute.toValue(offset, attributes.offset);
});

//Sandcastle_End
    Sandcastle.finishedLoading();
}
if (typeof Cesium !== 'undefined') {
    window.startupCalled = true;
    startup(Cesium);
}
</script>
</body>
</html>
